
*****************************************************************************************
**Replication Code for "Why Protectors become Predators? Violence against Civilians by AMISOM Peacekeepers in Somalia": Prabin B. Khadka (corresponding author:prabin.khadka@essex.ac.uk)
* version 18.0
clear all
set scheme s1mono // for white background
set more off
**set your working directory
cd "" 
pwd
************************************************************************************************************
************************************************************************************************************
*** Manuscript Figures / Tables / Graphs
** Figures related to SURVEY data. Codes for the Tables (in the online appendix) related to the figures in the main manuscript are right below the code for the figures.
use "~\SurveyData.dta",clear

global controls duration age male edu rank married prevAU_UN mil_ops pre_dep  i.dist	

************************************************************************************************************
************************************************************************************************************
*Figure 4: Impact of Peacekeeping casualties on Civilian Abuse: Attitudes and Behavior
*Tables related to Plots in Figure 4 are in the Online Appendix

*Figure 4 (Top Left Figure) "Attitudes: Reported witnessing an IED attack on Civilian Abuse(survey)"

eststo clear
eststo:reg troops_rec_perform_review  ied_face ${controls},cluster(fob1)
estimates store review1
eststo:reg coop_with_others  ied_face  ${controls},cluster(fob1)
estimates store coop1
eststo:reg complain  ied_face  ${controls},cluster(fob1)
estimates store compln1
eststo:reg relations  ied_face  ${controls},cluster(fob1)
estimates store rel1
eststo:reg civ_casual  ied_face ${controls},cluster(fob1)
estimates store civ_cas1
eststo:reg  attack  ied_face ${controls},cluster(fob1)
estimates store atk1
eststo:reg index_humanrights  ied_face  ${controls},cluster(fob1)
estimates store index1

coefplot   (review1, mlabel ("{it:Protection of civilians is essential}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
(coop1, mlabel("{it:Cooperation with civil society }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
(compln1, mlabel("{it:Civilians have right to complain}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
(rel1, mlabel("{it:Treat Somalis well}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
(civ_cas1, mlabel("{it:No civilian casualties}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
(atk1, mlabel("{it:Non military options to defeat AS}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
 (index1, mlabel("{it:Human rights index}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
, levels(95 ) keep(ied_face ) graphregion(fcolor(white))title("Attitudes: Reported witnessing an IED attack on" "Civilian Abuse(survey)") xline(0, lwidth(thin))  ///
 omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 

* Table A5-Online Appendix: Peacekeeping casualties on Civilian Abuse: Survey with self-reported IED attacks
esttab using TableA5.rtf, replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) keep (ied_face _cons) mtitles("POC essential"  "Co-op with civ soc"  "Right to complain"  "Treating well obstacle" "Civilian casualties"  "Solution is attacking" "HR index")

*******
*Figure 4 (Right Figure) "Attitudes: Real geo-coded IED attacks" "on Civilian Abuse (survey)"
eststo clear
eststo:reg troops_rec_perform_review  totaliedsincearvl  ${controls},cluster(fob1)
estimates store review
eststo:reg coop_with_others  totaliedsincearvl  ${controls},cluster(fob1)
estimates store coop
eststo:reg complain  totaliedsincearvl  ${controls},cluster(fob1)
estimates store compln
eststo:reg relations  totaliedsincearvl ${controls},cluster(fob1)
estimates store rel
eststo:reg civ_casual  totaliedsincearvl ${controls},cluster(fob1)
estimates store civ_cas
eststo:reg  attack  totaliedsincearvl ${controls},cluster(fob1)
estimates store atk
eststo:reg index_humanrights  totaliedsincearvl  ${controls},cluster(fob1)
estimates store index

coefplot   (review, mlabel ("{it:Protection of civilians is essential}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
(coop, mlabel("{it:Cooperation with civil society }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
 (compln, mlabel("{it:Civilians have right to complain}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
  (rel, mlabel("{it:Treat Somalis well }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
      (civ_cas, mlabel("{it:No civilian casualties}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
	  (atk, mlabel("{it:Non military options to defeat AS}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
	  (index, mlabel("{it:Human rights index}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
 , levels(95) keep(totaliedsincearvl ) graphregion(fcolor(white))title("Attitudes: Real geo-coded IED attacks" "on Civilian Abuse (survey)") xline(0, lwidth(thin))  ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 

* Table A6-Online Appendix: Peacekeeping casualties and Civilian Abuse: Survey w/geo-coded IED attacks
esttab using TableA6.rtf, replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) keep (totaliedsincearvl _cons) mtitles("POC essential"  "Co-op with civ soc"  "Right to complain"  "Treating well obstacle" "Civilian casualties"  "Solution is attacking" "HR index")
***********
*Table A5- col. 9 for M.I. (multiple imputation for missing value) 
* Reference: https://www.stata.com/meeting/boston10/boston10_marchenko.pdf

misstable summarize  //  displays missing value
misstable patterns
drop if ied_face==.

mi set mlong
mi register imputed index_humanrights

mi impute regress index_humanrights ied_face , add(5) rseed(123)	
mi estimate: regress index_humanrights ied_face ${controls},cluster(fob1) 

* IMPORTANT. U need to clear the data and load data all again to carry out the below for MI. since the exisiting data will already be imputed for all variables. 
*Table A6- col. 6 for M.I. (multiple imputation for missing value) 
clear all
use "~\SurveyData.dta",clear
misstable summarize  //  displays missing value
misstable patterns

mi set mlong
mi register imputed index_humanrights
drop if totaliedsincearvl==.

mi impute regress index_humanrights totaliedsincearvl, add(20) rseed(1234)	
mi estimate: regress index_humanrights totaliedsincearvl  ${controls},cluster(fob1) 

************************************************************************************************************
** Figure 4: Behavior
***********
clear all
use "~/BehaviorData.dta"
** Figure 4- Behavior 1 (Bottom Left)
eststo clear
eststo:xi:reg civcas iedattack 
estimates store one
eststo:xi:reg  civcas iedattack  rainfall ramadaan 
estimates store two
eststo:xi:reg  civcas iedattack  rainfall ramadaan  i.location i.year
estimates store three
eststo:xi:reg  civcas iedattack  rainfall ramadaan  i.region i.year
estimates store four

coefplot   (one, mlabel ("{it:Without covariates}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)  ciopts(lcolor(black))) ///
(two, mlabel("{it:With covariates }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)   ciopts(lcolor(black))) ///
 (three, mlabel("{it:With covariates, Location & Year FE}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)   ciopts(lcolor(black))) ///
  (four, mlabel("{it:With covariates, Region & Year FE}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
 , levels(95) keep( iedattack ) graphregion(fcolor(white))title("Behavioral 1: Real time IED attacks" "on real time Civilian Abuse") xline(0, lwidth(thin)) lcolor(red) ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 

** Figure 4- Behavior 2 (Bottom Right)
eststo clear
eststo:xi:reg  civcas am_offen  rainfall ramadaan i.location i.year
estimates store one_am
eststo:xi:reg  civcas am_offen  rainfall ramadaan  i.region i.year
estimates store two_am

coefplot   (one_am, mlabel ("{it:AMISOM Offensive Ops-With covariates, Loc. & Year FE}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)  ciopts(lcolor(black))) ///
(two_am, mlabel("{it:AMISOM Offensive Ops-With covariates, Reg. & Year FE }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)   ciopts(lcolor(black))) ///
 , levels(95) keep( am_offen) graphregion(fcolor(white))title("Behavior2:Effect of AMISOM Offensive Ops" "on real time Civilian Abuse") xline(0, lwidth(thin)) lcolor(red) ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 

* Table B9: Impact of IED Attacks / AMISOM Offensive Ops on Civilian Abuse: Behavioral
eststo clear
eststo:xi:reg civcas iedattack 
estimates store one
eststo:xi:reg  civcas iedattack  rainfall ramadaan 
estimates store two
eststo:xi:reg  civcas iedattack  rainfall ramadaan  i.location i.year
estimates store three
eststo:xi:reg  civcas iedattack  rainfall ramadaan  i.region i.year
estimates store four
eststo:xi:reg  civcas am_offen  rainfall ramadaan  i.location i.year
estimates store five
eststo:xi:reg  civcas am_offen  rainfall ramadaan  i.region i.year
estimates store six

esttab using  TableB9.rtf, replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) keep(iedattack am_offen _cons) ti("Results: Behavioral") addnotes("Controls include rainfall on the day of the incident and Ramadaan dummy. (p-values are for two-sided tests.)")
***********

**************************************************************************************************************
* Table 2: Mechanism- Revenge or Strategic Objective/Show Of Force
* Reload Survey data since multiple imputation carried out above
clear all
use "~\SurveyData.dta",clear
global controls dur age male edu rank married prevAU_UN mil_ops pre_dep  i.dist	

* Revenge
*a) Friend Killed*Witnessed IED attack
gen kill_dummy=0
replace kill_dummy=1 if killed>0
tab kill_dummy
tab killed

gen kill_repdummy_ied=ied_face*kill_dummy

eststo clear
reg index_humanrights  ied_face kill_dummy kill_repdummy_ied ${controls},cluster(fob1) 
esttab,keep(kill_repdummy_ied ied_face kill_dummy _cons) b(2) se(2) cons replace star(* 0.1 ** 0.05 *** 0.01 ) r2  ti("Reported killings interacted with reported IED attack") addnotes("Robust standard errors clustered by forward operating base (FOB). (p-values are for two-sided tests.)")

* b) Friend Injured*Witnessed IED attack

gen injr_dummy=0
replace injr_dummy=1 if injury>0
tab injr_dummy
tab injury

gen injr_repdummy_ied=ied_face*injr_dummy

eststo clear
reg index_humanrights  injr_repdummy_ied injr_dummy ied_face ${controls},cluster(fob1) 
esttab,keep(injr_repdummy_ied injr_dummy ied_face _cons) b(2) se(2) cons replace star(* 0.1 ** 0.05 *** 0.01 ) r2  ti("Reported killings interacted with reported IED attack") addnotes("Robust standard errors clustered by forward operating base (FOB). (p-values are for two-sided tests.)")

*****
*Show of Force/ Strategic Objective

*a) Under Fire from AS*Witnessed IED attack
gen fire_face=0
replace fire_face=1 if fire>0
gen ied_fire_dummy=fire_face*ied_face

eststo clear
reg index_humanrights ied_fire_dummy fire ied_face ${controls},cluster(fob1) 
esttab,keep(ied_fire_dummy fire ied_face _cons) b(2) se(2) cons replace star(* 0.1 ** 0.05 *** 0.01 ) r2  ti("Reported killings interacted with reported IED attack") addnotes("Robust standard errors clustered by forward operating base (FOB). (p-values are for two-sided tests.)")

*b) Offensive Ops against AS*Witnessed IED attack
gen AS_fight_dummy=0
replace AS_fight_dummy=1 if AS_fight>0

gen AS_fight_ied=AS_fight*ied_face

eststo clear
reg index_humanrights AS_fight_ied AS_fight ied_face ${controls},cluster(fob1) 

esttab,keep(AS_fight_ied AS_fight ied_face _cons) b(2) se(2) cons replace star(* 0.1 ** 0.05 *** 0.01 ) r2  ti("Reported killings interacted with reported IED attack") addnotes("Robust standard errors clustered by forward operating base (FOB). (p-values are for two-sided tests.)")

**************************************************************************************************************
**Table 3: Mediation Check
**Table 3: Mediation Check- (1) Attitude Survey-self reported AMISOM casualties)

sgmediation2 index_humanrights, mv(casualty) iv(ied_face) 

**Table 3: Mediation Check- (2) Attitude Survey-real time AMISOM casualties)

sgmediation2 index_humanrights, mv(amsm_cas) iv(ied_face) 


**Table 3: Mediation Check- (3) Behavior-Observational
clear all
use "BehaviorData.dta "
sgmediation2 civcas, mv(am_kill) iv(iedattack)


******************************************************************************************************************** Survey Experiment
**************************************************************************************************************
clear all
use " UN_AMISOM_data.dta""

* Figure 6 (Right): Impact of Violence Exposure Perceived Civilian Abuse Ethiopians in AMISOM Somalia vs Ethiopians in South Sudan
eststo clear
eststo:reg troops_rec_perform_review  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store review
eststo:reg coop_with_others  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store coop
eststo:reg complain  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store compln
eststo:reg relations  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store rel
eststo:reg civ_casual  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store civ_cas
eststo:reg  attack  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store atk
eststo:reg index_humanrights  ehthiopiaamisomdummy duration age male education rank married prevAU_UN mil_ops pre_dep
estimates store index


coefplot   (review, mlabel ("{it:Protection of civilians is essential}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
(coop, mlabel("{it:Cooperation with civil society }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
 (compln, mlabel("{it:Civilians have right to complain}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
  (rel, mlabel("{it:Treat locals well}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
      (civ_cas, mlabel("{it:No civilian casualties}") mlabposition(clockposlist 11)mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
	  (atk, mlabel("{it:Non military options}" ) mlabposition(clockposlist 1) mlabcolor(black) mcolor(red) msymbol(triangle) msymbol(square)  ciopts(lcolor(black))) ///
	  (index, mlabel("{it:Human rights index}") mlabposition(clockposlist 11)mlabposition(clockposlist 1) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
 , levels(95) keep( ehthiopiaamisomdummy ) graphregion(fcolor(white))title("Impact of Violence Exposure Perceived Civilian Abuse:" "Ethiopians in AMISOM Somalia vs Ethiopians in South Sudan") xline(0, lwidth(thin)) lcolor(red) ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 

* Table C13: External Validity: Ethiopians in AMISOM vs Ethiopians in South Sudan
esttab using TableC13.rtf, replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) keep (ehthiopiaamisomdummy _cons) mtitles("POC essential"  "Co-op with civ soc"  "Right to complain"  "Treating well obstacle" "Civilian casualties"  "Solution is attacking" "HR index")
******
********************************************************************************************************************SURVEY EXPERIMENT
* Figure 6: Results (Left): Survey Experiment with Kenyan PKs in Somalia and Comparison of Ethiopian PKs in Somalia with Ethiopian PKs in South Sudan 
clear all
use "~/ExperimentData.dta "
 
		
eststo clear
eststo:reg troops_rec_perform_review treatment age male education married rank prevAU_UN
estimates store review
eststo:reg coop_with_others	treatment age male education married rank prevAU_UN
estimates store coop
eststo:reg complain	treatment age male education married rank prevAU_UN
estimates store compln
eststo:reg relations treatment age male education married rank prevAU_UN
estimates store rel
eststo:reg civ_casual  treatment  age male education married rank prevAU_UN	
estimates store civ_cas
eststo:reg attack treatment age male education married rank prevAU_UN	
estimates store atk
eststo:reg index_survey  treatment  
estimates store index_nocontrol
eststo:reg index_survey  treatment age male education married rank prevAU_UN	
estimates store index

			
 // Graphs
coefplot   (review, mlabel ("{it:Protection of civilians is essential}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)ciopts(lcolor(black))) ///
(coop, mlabel("{it:Cooperation with civil society }") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)  ciopts(lcolor(black))) ///
 (compln, mlabel("{it:Civilians have right to complain}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle)  ciopts(lcolor(black))) ///
  (rel, mlabel("{it:Treat locals well}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square)  ciopts(lcolor(black))) ///
      (civ_cas, mlabel("{it:No civilian casualties}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
	  (atk, mlabel("{it:Non military options}") mlabposition(clockposlist 3) mlabcolor(black) msymbol(square) mcolor(black)   ciopts(lcolor(black))) ///
	  (index_nocontrol, mlabel("{it:Human rights index (no cov.)}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
	  	  (index, mlabel("{it:Human rights index (cov.)}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(red) msymbol(triangle) ciopts(lcolor(black))) ///
 , levels(95) keep( treatment ) graphregion(fcolor(white))title("Experimental Results: Impact of Violence on Civilian Abuse") xline(0, lwidth(thin)) lcolor(red) ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 
 


* Table C11: Experimental Results: Impact of Violence on Civilian Abuse
foreach var of varlist troops_rec_perform_review /// 
						coop_with_others ///
						complain ///
						relations ///
						civ_casual ///
						attack ///
					  index_survey { 
			qui xi: reg `var' treatment  
			   outreg2 using  Table.C11, replace  keep (treatment)
			}		
 
* Table C11- column 8 with co-variates
foreach var of varlist troops_rec_perform_review /// 
						coop_with_others ///
						complain ///
						relations ///
						civ_casual ///
						attack ///
					  index_survey { 
			qui xi: reg `var' treatment  age male education married rank prevAU_UN	
			   outreg2 using  Table.C11_1, replace keep (treatment)
			}		
 
 
 
 
** Table C10: Balance Test- Survey Experiment with Kenyans (Treatment vs Control)
eststo clear
foreach var of varlist age male education married rank prevAU_UN { 
			eststo: reg `var' treatment,robust
			   esttab using "exp_balance.rtf", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) ti("Balance - Survey Experiment with Kenyans") addnotes("(p-values are for two-sided tests.)") mtitles("Age"  "Sex"  "Edu."  "Marry" "Rnk"  "Prev. AMISOM/UN" )
			}


************** Graphs

clear all
use "~\ConvoyData.dta"

*Figure 2: IED hits against AMISOM convoys in Sector 1
preserve
keep if Sec==1
collapse  (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
xtitle("") ytitle("Convoys and IED hits, daily totals") title("Sector 1: Uganda") ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore


** Fig D11

preserve
collapse (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
    xtitle("") ytitle("Convoys and IED hits, daily totals") title("All six sectors") ///
    xlabel(#15, angle(45)) ///
    ylabel(#8) ///
    lcolor(blue red) ///
    legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore

preserve
keep if Sec==2
collapse  (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
xtitle("") ytitle("Convoys and IED hits, daily totals") title("Sector 2: Kenya") ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore

preserve
keep if Sec==3
collapse  (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
xtitle("") ytitle("Convoys and IED hits, daily totals") title("Sector 3: Ethiopia") ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore

preserve
keep if Sec==4
collapse  (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
xtitle("") ytitle("Convoys and IED hits, daily totals") title("Sector 4: Djibouti/Ethiopia") ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore

preserve
keep if Sec==5
collapse  (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
xtitle("") ytitle("Convoys and IED hits, daily totals") title("Sector 5: Burundi")  ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore

preserve
keep if Sec==6
collapse  (sum) convoy ied, by(date)
twoway bar convoy ied date, ///
xtitle("") ytitle("Convoys and IED hits, daily totals") title("Sector 6: Kenya/Ethiopia/Burundi")  ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "(sum) convoy") label(2 "(sum) ied") position(6) cols(2))
restore
********************************************************************************************
* Figure 3: IED Attacks: AMISOM versus others and AMISOM casualties from IED attacks
clear all

use "~\IEDgraphData.dta", clear

line IED_AMISOM IED_Others Date, ///
    xtitle("") ytitle("IED attacks-Monthly Cumulative") ///
    xlabel(#10, angle(45)) ///
    lcolor(blue red) lpattern(solid dash) ///
    legend(order(1 2) label(1 "Against AMISOM only") label(2 "All other attacks") position(6) cols(2))
	graph save amisom1, replace
	
line AMISOM_Kill Date, ///
    xtitle("") ytitle("AMISOM peacekeepers killed daily totals") ///
    xlabel(#10, angle(45)) ///
    lcolor(blue) 
    graph save amisom2, replace

	graph combine  amisom1.gph amisom2.gph, xsize(12) ysize(4)



************************************************************************************************************
************************************************************************************************************
** Online Appendix
*** Manuscript Figures / Tables / Graphs
** Figures related to SURVEY data
clear all
use "~\SurveyData.dta",clear

global controls duration age male edu rank married prevAU_UN mil_ops pre_dep  i.dist	


* Summary stats
** Table A 4: Summary statistics of AMISOM Peacekeepers in Somalia
gen Kenya=0
replace Kenya=1 if TCC=="Kenya"

gen Uganda=0
replace Uganda=1 if TCC=="Uganda"

gen Eth=0
replace Eth=1 if TCC=="Ethiopia"

gen Burundi=0
replace Burundi=1 if TCC=="Burundi"


dtable male age married education rank prevAU_UN mil_ops pre_dep AS_fight injury killed ied_face totaliedsincearvl amsm_cas dur  Kenya Eth Burundi Uganda 


** Table A8: Factor Loading

pca troops_rec_perform_review coop_with_others complain relations civ_casual attack

// below will show eigenvalues on a graphregion- Factor1: 1.52 and Factor2: 1.21
screeplot, yline(1) ci(het)
predict pc1 pc2 pc3, score


** Column (8) for Table A5 (PCA): Peacekeeping casualties on Civilian Abuse: Survey with self-reported IED attacks
reg pc1 ied_face ${controls},cluster(fob1)

******
* Table A7: Correlation between the six survey outcomes

preserve
correlate troops_rec_perform_review coop_with_others complain relations civ_casual attack
matrix list r(C)
version 14.0
putexcel A1=matrix(r(C), names) using amisom_corr.xlsx, modify keepcellformat
restore


** Figure A8: Predictive Margins MARGIN Plots
** Left (Attitudinal)
reg index_humanrights  totaliedsincearvl dur age male edu rank married prevAU_UN mil_ops pre_dep  i.dist	,cluster(fob1)	
margins, at (totaliedsincearvl=(0 2 4 6 8 10 12 14 16 18 20 22 24 26 ))
marginsplot		


** Figure A8: Predictive Margins MARGIN Plots
** Right (Behavioral)
clear all
use "~\BehaviorData.dta"
xi:reg civcas iedattack  rainfall ramadaan  i.location i.year
margins, at (iedattack=(0 1 2 3 4 ))
marginsplot	


* Table C12: Balance Test - Ethiopians in AMISOM vs Ethiopians in South Sudan
clear all
use " UN_AMISOM_data.dta"
eststo clear
foreach var of varlist dur   age male edu rank married prevAU_UN mil_ops pre_dep { 
			eststo: reg `var' ehthiopiaamisomdummy,robust
			   esttab using "Balance_eth_ssudan.rtf", replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) ti("Balance - Ethiopians in AMISOM vs South Sudan") addnotes("(p-values are for two-sided tests.)") mtitles("Dur.""Age"  "Sex"  "Edu." "Rnk"  "Marry"  "Prev. AMISOM/UN" "Pre Dep. Trng.")
			}

*******************************************************************************			
clear all
use "~\ConvoyData.dta"
* Figure D10: IED attacks plotted against convoy strength (Jan 2018-March 2019)

preserve
collapse  (sum) armouredvehoftotalnoofvehicles numberofvehicles ied, by(date)
gen con_str= armouredvehoftotalnoofvehicles/numberofvehicles
twoway bar con_str ied date, ///
xtitle("") ytitle("Convoy strength in ratio (0-1) and IED attacks")  ///
xlabel(#15, angle(45)) ///
 lcolor(blue red) ///
legend(order(1 2) label(1 "convoy strength ration (0-1)") label(2 "ied attacks (0-3)") position(6) cols(2))
restore

*******************************************************************************

*Figure A7: Robustness Test- Results excluding each TCC
clear all
use "~\SurveyData.dta",clear
** run below (till the single line ****) at one go	

global controls duration age male edu rank married prevAU_UN mil_ops pre_dep  i.dist	


eststo clear
reg index_humanrights ied_face ${controls} if TCC!="Burundi", cluster(fob1)
estimates store iedface_nobur
reg index_humanrights  ied_face  ${controls} if TCC!="Kenya",cluster(fob1)
estimates store iedface_noken	
estimates store iedface_noken	
reg index_humanrights  ied_face  ${controls} if TCC!="Ethiopia",cluster(fob1)
estimates store iedface_noeth
reg index_humanrights  ied_face  ${controls} if TCC!="Uganda",cluster(fob1)
estimates store iedface_noug	

eststo clear
eststo:reg index_humanrights  totaliedsincearvl  ${controls} if TCC!="Burundi",cluster(fob1)
estimates store index_nobur
eststo:reg index_humanrights  totaliedsincearvl  ${controls} if TCC!="Kenya",cluster(fob1)
estimates store index_noken
eststo:reg index_humanrights  totaliedsincearvl  ${controls} if TCC!="Ethiopia",cluster(fob1)
estimates store index_noeth
eststo:reg index_humanrights  totaliedsincearvl  ${controls} if TCC!="Uganda",cluster(fob1)
estimates store index_noug

// Graphs-
coefplot   (iedface_nobur, mlabel ("{it:Human rights index w/out Burundi}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
 (iedface_noken, mlabel ("{it:Human rights index w/out Kenya}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
 (iedface_noeth, mlabel ("{it:Human rights index w/out Ethiopia}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
  (iedface_noug, mlabel ("{it:Human rights index w/out Uganda}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
       , levels(95 90) keep(ied_face ) graphregion(fcolor(white))title("Attitudes: Reported witnessing an IED attack on" "Civilian Abuse (survey)") xline(0, lwidth(thin))  ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 
graph save survey_ied, replace

coefplot   (index_nobur, mlabel ("{it:Human rights index w/out Burundi}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
 (index_noken, mlabel ("{it:Human rights index w/out Kenya}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
 (index_noeth, mlabel ("{it:Human rights index w/out Ethiopia}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
  (index_noug, mlabel ("{it:Human rights index w/out Uganda}") mlabposition(clockposlist 11) mlabcolor(black) mcolor(black) msymbol(square) ciopts(lcolor(black))) ///
       , levels(95 90) keep(totaliedsincearvl ) graphregion(fcolor(white))title("Attitudes: Real geo-coded IED attacks" "on Civilian Abuse (survey)") xline(0, lwidth(thin))  ///
omitted yscale(off) mlabsize(medium) legend(off) graphregion(fcolor(white)) 
graph save real_ied, replace
graph combine  survey_ied.gph  real_ied.gph
graph export "A7.pdf", replace

************************************************************************************************************** 
** Table C15: Pre-Operational Brief on Civilian Abuse
eststo clear
eststo:reg troops_rec_perform_review  pre_convoy_brief   ${controls},cluster(fob1)
estimates store review
eststo:reg coop_with_others  pre_convoy_brief   ${varlist},cluster(fob1)
estimates store coop
eststo:reg complain  pre_convoy_brief  ${controls},cluster(fob1)
estimates store compln
eststo:reg relations  pre_convoy_brief  ${controls},cluster(fob1)
estimates store rel
eststo:reg civ_casual  pre_convoy_brief  ${controls},cluster(fob1)
estimates store civ_cas
eststo:reg  attack  pre_convoy_brief  ${controls},cluster(fob1)
estimates store atk
eststo:reg index_humanrights  pre_convoy_brief   ${controls},cluster(fob1)
estimates store index

 esttab using TableC15.rtf, replace b(2) se(2) l star(* 0.1 ** 0.05 *** 0.01) r2(2) keep (pre_convoy_brief _cons) mtitles("POC essential"  "Co-op with civ soc"  "Right to complain"  "Treating well obstacle" "Civilian casualties"  "Solution is attacking" "HR index")
 
*******************END***************************************************************************
